<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Car extends Model
{
    protected $table='park_carinfo';
    protected $guarded=[];
    protected $primaryKey='CarID';
    public $timestamps=false;
    
    public function scopeForSell($query)
    {
        return $query->where('forSell',1);
    }
    
    public function getCredit()
    {
        return $this->attributes['CarPrice'];
    }
    
    public function getIdAttribute()
    {
        return $this->attributes['CarID'];
    }
    //是否为新能源车
    public function isNewEnergy()
    {
        return $this->attributes['CarType'] == 2;
    }
    
    public function getCarCreditHourAttribute()
    {
        return $this->attributes['CarCredit']*60;
    }
    
    public function getCarImgBigAttribute()
    {
        if(!$this->attributes['CarImgBig'])return '';
        return starts_with($this->attributes['CarImgBig'],'http') ? $this->attributes['CarImgBig'] : config('filesystems.disks.admin.url').$this->attributes['CarImgBig'];
    }
    
    public function getCarImgAttribute()
    {
        if(!$this->attributes['CarImg'])return '';
        return starts_with($this->attributes['CarImg'],'http') ? $this->attributes['CarImg'] : config('filesystems.disks.admin.url').$this->attributes['CarImg'];
    }
    public function getCarSignAttribute()
    {
        if(!$this->attributes['CarSign'])return '';
        return starts_with($this->attributes['CarSign'],'http') ? $this->attributes['CarSign'] : config('filesystems.disks.admin.url').$this->attributes['CarSign'];
    }
    
    public function getCarColorAttribute()
    {
        return array_key_exists($this->attributes['CarColor'],config('car.cfgCarType'))?config('car.cfgCarType')[$this->attributes['CarColor']]:'';
    }
    
    public function stages()
    {
        return $this->belongsToMany(Stage::class,'park_mystage','car_id','StageID');
    }
    
    
}
